# Search user-installed locations first, so that we prefer user installs
# to system installs where both exist.
list(APPEND GLOG_CHECK_INCLUDE_DIRS
        /usr/local/include
        /usr/local/homebrew/include # Mac OS X
        /opt/local/var/macports/software # Mac OS X.
        /opt/local/include
        /usr/include)
# Windows (for C:/Program Files prefix).
list(APPEND GLOG_CHECK_PATH_SUFFIXES
        glog/include
        glog/Include
        Glog/include
        Glog/Include
        google-glog/include # CMake installs with project name prefix.
        google-glog/Include)

list(APPEND GLOG_CHECK_LIBRARY_DIRS
        /usr/local/lib
        /usr/lib/x86_64-linux-gnu
        /usr/local/homebrew/lib # Mac OS X.
        /opt/local/lib
        /usr/lib)
# Windows (for C:/Program Files prefix).
list(APPEND GLOG_CHECK_LIBRARY_SUFFIXES
        glog/lib
        glog/Lib
        Glog/lib
        Glog/Lib
        google-glog/lib # CMake installs with project name prefix.
        google-glog/Lib)

# Search supplied hint directories first if supplied.
find_path(Glog_INCLUDE_DIR
        NAMES glog/logging.h
        HINTS ${GLOG_INCLUDE_DIR_HINTS}
        PATHS ${GLOG_CHECK_INCLUDE_DIRS}
        PATH_SUFFIXES ${GLOG_CHECK_PATH_SUFFIXES})

find_library(Glog_LIBRARY NAMES glog
        HINTS ${GLOG_LIBRARY_DIR_HINTS}
        PATHS ${GLOG_CHECK_LIBRARY_DIRS}
        PATH_SUFFIXES ${GLOG_CHECK_LIBRARY_SUFFIXES})

message(STATUS "Glog inc: ${Glog_INCLUDE_DIR} lib: ${Glog_LIBRARY}")

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Glog DEFAULT_MSG Glog_INCLUDE_DIR Glog_LIBRARY)

mark_as_advanced(Glog_INCLUDE_DIR Glog_LIBRARY)

if(Glog_FOUND)
    message(STATUS =====${Glog_VERSION})
    if (NOT TARGET glog::glog)
        add_library(glog::glog INTERFACE IMPORTED)
        target_link_libraries(glog::glog INTERFACE ${Glog_LIBRARY})
        target_include_directories(glog::glog INTERFACE ${Glog_INCLUDE_DIR})
    endif()
endif()